package com.lavida.project.system.emp.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import com.lavida.project.system.emp.domain.Roster;

public interface RosterMapper {
	List<Roster> selectRoster(Roster roster);
	
	int insertRoster(Roster roster);
	
	//删除花名册员工信息
	int deleteRoster(int job_id);
	
	
	Roster getRoster(int job_id);
	
	int updateRoster(Roster roster);
	
	List<Roster> selectRosters();
	
	Roster selectRosterscard(String id_card);
	/**
	 * 获取本月/上个月 在职/离职人数
	 * @param colName
	 * @param interval
	 * @return
	 */
	@Select("SELECT COUNT(job_id) FROM roster WHERE YEAR(${colName}) = DATE_FORMAT(DATE_SUB(CURDATE(), INTERVAL #{interval} MONTH), '%Y') AND MONTH(${colName}) =  DATE_FORMAT(DATE_SUB(CURDATE(), INTERVAL #{interval} MONTH), '%m')")
	Integer selectIntervalMonthEmpNums(@Param("colName")String colName,@Param("interval")int interval);
	/**
	 * 获取本年度各月月初在职人数
	 * @param month
	 */
	@Select("SELECT COUNT(job_id) FROM roster WHERE STATUS = '在职' AND hiredate <=  CONCAT(YEAR(CURDATE()),'-',#{month},'-','01') AND (leavetime IS NULL OR leavetime > CONCAT(YEAR(CURDATE()),'-',#{month},'-','01'))")
	Integer selectBeginMonthWorkEmpNums(String month);
	/**
	 * 获取本年度各月月末在职人数
	 * @param month
	 * @return
	 */
	@Select("SELECT COUNT(job_id) FROM roster WHERE STATUS = '在职' AND (leavetime IS NULL OR leavetime > LAST_DAY(CONCAT(YEAR(CURDATE()),'-',#{month},'-','01')))")
	Integer selectEndMonthWorkEmpNums(@Param("month")String month);
	
}
